package com.wugh.fast.module.mapper.interceptor.plugin;

import com.wugh.fast.module.mapper.EntityInfo;
import lombok.Getter;
import tk.mybatis.mapper.entity.EntityColumn;

import java.util.Set;

/**
 * 说明: 字段名插件抽象类
 *
 * @author wugh
 * @date 2019-01-17 14:42
 */
@Getter
public abstract class AbstractFieldNamePlugin extends AbstractPlugin {
    private String fieldName;
    private EntityColumn column;

    public AbstractFieldNamePlugin(String fieldName) {
        this.fieldName = fieldName;
    }

    @Override
    public boolean support(EntityInfo entityInfo) {
        super.support(entityInfo);
        Set<EntityColumn> columns = entityInfo.getEntityTable().getEntityClassColumns();
        for (EntityColumn column : columns) {
            if (column.getEntityField().getName().equals(this.fieldName)) {
                this.column = column;
                return true;
            }
        }
        return false;
    }
}
